feat: Constructor generic type inference#2894
feat: Constructor generic type inference#2894CountBleck merged 6 commits intoAssemblyScript:mainfrom
Conversation
|
Note - I didn't change any of the actual existing logic for type inference that was used for functions. I just extracted it for re-use by constructor "new expressions". The PR is best reviewed with the "hide whitespace" box checked. |
|
@mattjohnsonpint Thanks, that diff looks so much more manageable to review now. |
|
Note: it doesn't handle this case: class Foo<T> {
constructor(public x: T) {}
}
class Bar<T> extends Foo<T> {}
const x = new Bar("hi")That can probably be figured out at a later date. |
CountBleck
left a comment
There was a problem hiding this comment.
This looks good, probably.
I might be able to address that. I'll take a look tomorrow. Good catch! |
|
It should handle that case now. Thanks! |
|
Also, FWIW, I don't think either of the previously existing test cases marked |
I don't know what those are for either. I'm guessing it's something related to omitting |
Fixes #2893.
Changes proposed in this pull request:
Enables type inference for constructors of generic classes by:
Refactoring to extract the existing type inference logic for functions that was in
maybeInferCall, into its own private methodinferGenericTypeArguments.Calling that new method from
resolveClassInclTypeArgumentswhen a generic class's constructor is called without any type arguments.Expanding the unit tests to verify working functionality and no regressions.
I've read the contributing guidelines
I've added my name and email to the NOTICE file